#include <string>
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int q=0;
string v="", k="", y="";
getline(cin, v);
for(int i = 0; i<v.size(); i++){
    if(v[i]==' ' || i==v.size()-1){
        if(i==v.size()-1)
            k+=v[i];
        if(k=="zero")
            y+="0";
        else if(k=="one")
             y+="1";
        else if(k=="two")
             y+="2";
        else if(k=="three")
             y+="3";
        else if(k=="four")
             y+="4";
        else if(k=="five")
             y+="5";
        else if(k=="six")
             y+="6";
        else if(k=="seven")
             y+="7";
        else if(k=="eight")
             y+="8";
        else if(k=="nine")
             y+="9";
        k="";
    }
    else
        k+=v[i];
}
if(y.size()!=3 || y[0]=='0')
    cout<<"Wrong input";
else
{
    q=stoi(y);
    bool a=true;
    int m, mm;
    for(int j = q;j<=q+10;j++){
        a = true;
        for(int i = 2; i<=int(sqrt(j));i++){
            if(j%i==0){
                a=false;
                break;}
            }
        if(a){
            m=j;
            break;
        }
    }
    for(int j = q;j>=q-10;j--){
        a = true;
        for(int i = 2; i<=int(sqrt(j));i++){
            if(j%i==0){
                a=false;
                break;}
            }
        if(a){
            mm=j;
            break;
        }
    }
    if(m-q<q-mm)
        cout<<m;
    else if (m-q>q-mm ||m-q==q-mm)
        cout<<mm;
}
}
